{template 'common/header'}
<script>
    $(function(){
        $(".find_goods").click(function(){
            var key_word = $("#key_word").val();
            if(key_word != ''){
                location.href="{php echo $this->createWebUrl('members',array('op' => 'goods', 'member_id' => $member_id))}&key_word="+key_word;
            }
        });
        $(".del_member_goods").click(function(){
            var id = $(this).attr('member_goods_id');
            if(id > 0){
                var url = "{php echo $this->createWebUrl('members',array('op' => 'del_member_goods'))}";
                $.ajax({
                    type : "post",
                    url : url,
                    data : {'id' : id},
                    success : function(data){
                        if(data == 111){
                            alert("操作成功！");
                            location.reload();
                        }else{
                            alert(data);
                        }
                    }
                });
            }
        });
        $(".change_price").blur(function(){
            var new_price = $(this).val();
            var id = $(this).attr('mg_id');
            if(new_price > 0){
                var url = "{php echo $this->createWebUrl('members',array('op' => 'change_price'))}";
                $.ajax({
                    type : "post",
                    url : url,
                    data : {'id' : id , 'price' : new_price},
                    success : function(data){
                        if(data == 111){
                            alert("修改成功！");
                        }else{
                            alert(data);
                        }
                    }
                });
            }
        });
    });

    function add(goods_id){
        if(goods_id > 0){
            var url = "{php echo $this->createWebUrl('members',array('op' => 'add_goods'))}";
            var member_id = "{$member_id}";
            $.ajax({
                type : "post",
                url : url,
                data : {'goods_id' : goods_id, 'member_id' : member_id},
                success : function(data){
                    if(data == 111){
                        alert("操作成功！");
                        location.reload();
                    }else{
                        alert(data);
                    }
                }
            });
        }
    }
</script>
<ul class="nav nav-tabs">
    <li class="active" ><a href="{php echo $this->createWebUrl('members', array('op'=>'index'))}">客户列表</a></li>
    <li ><a href="{php echo $this->createWebUrl('members', array('op'=>'add'))}">新增客户</a></li>
</ul>
<div class="main">
    <div class="col-xs-6">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <div class="panel-title">
                    固定商品
                </div>
            </div>
            <div class="panel-body">
                <table class="table">
                    <tr>
                        <th>商品</th>
                        <th>单位</th>
                        <th>运费</th>
                        <th>删除</th>
                    </tr>
                    {loop $member_goods $m_goods}
                    <tr>
                        <td>{$m_goods['name']}</td>
                        <td>{$m_goods['unit']}</td>
                        <td>
                            <input type="text" class="form-control change_price" mg_id="{$m_goods['id']}" value="{$m_goods['price']}" style="width:160px;" />
                        </td>
                        <td>
                            <button class="btn btn-danger del_member_goods" member_goods_id="{$m_goods['id']}">删除</button>
                        </td>
                    </tr>
                    {/loop}
                </table>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <div class="panel-title">
                    选择固定商品
                </div>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-1">

                    </div>
                    <div class="col-xs-6">
                        <input type="text" class="form-control" placeholder="商品名/助记码" value="{$key_word}" id="key_word" />
                    </div>
                    <div class="col-xs-4">
                        <button class="btn btn-primary find_goods">搜索</button>
                    </div>
                    <div class="col-xs-1"></div>
                </div>
                <br />
                <table class="table">
                    <tr>
                        <th>商品</th>
                        <th>助记码</th>
                        <th>单位</th>
                        <th>运费</th>
                        <th>删除</th>
                    </tr>
                    {loop $goods_list $goods}
                    <tr>
                        <td>{$goods['name']}</td>
                        <td>{$goods['short_name']}</td>
                        <td>{$goods['unit']}</td>
                        <td>{$goods['price']}</td>
                        <td>
                            <button class="btn btn-primary" onclick="add({$goods['id']});">添加</button>
                        </td>
                    </tr>
                    {/loop}
                </table>
                <div>{$pager}</div>
            </div>
        </div>
    </div>
</div>
{template 'common/footer'}